﻿<%@ page language="java" 
	contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>添加结果</title>
</head>
<body>

<%
   request.setCharacterEncoding("utf-8");

   String uname = request.getParameter("uname");
   String upassword = request.getParameter("upassword");

	// 加载数据库驱动，注册到驱动管理器
    Class.forName("com.mysql.jdbc.Driver");
	// 连接数据库
    String url = "jdbc:mysql://localhost:3306/user2?useUnicode=true&characterEncoding=utf-8";
    String username = "root";
    String password = "1234";
    Connection conn = DriverManager.getConnection(url,username,password);
   
    // 获取数据库操作对象
    Statement stmt = conn.createStatement();
	// 构造SQL语句
	String sql = "insert into user_b(uname,upassword) values ('" + uname + "','" + upassword + "')";
	System.out.print(sql);

	// 执行更新操作，返回所影响的行数
	int n = stmt.executeUpdate(sql);
	// 判断是否更新成功
	if(n > 0){
	    // 更新成功输出信息
	    out.print("成功添加了 " + n + "条数据！");
	}	  
	if(stmt != null){ 
		stmt.close();	
	}
	if(conn != null){
		conn.close();	
	}
	
%>
	<br>
	<a href="index.jsp">返回</a>
</body>
</html>